Provide support for commands - #21
Conversation
2011a25 to
7471a0c
Compare
|
Actually, having looked at that disgusting applyEdit function, we should iterate over the changes and then apply them all in bulk. Otherwise the undo stack looks a bit odd. |
akosyakov
left a comment
There was a problem hiding this comment.
Thanks for looking into it. Please see comments.
Most important to have a proof that it is working, e.g. with the JSON example server. Please add a command that does workspace edits to demonstrate it.
|
|
||
| public applyEdit(workspaceEdit: WorkspaceEdit): Thenable<boolean> { | ||
| let applied = true; | ||
| if (workspaceEdit.documentChanges) { |
There was a problem hiding this comment.
please use asWorkspaceEdit, applying documentChanges is not enough
| return this.onDidChangeTextDocumentEmitter.event; | ||
| } | ||
|
|
||
| public applyEdit(workspaceEdit: WorkspaceEdit): Thenable<boolean> { |
| let applied = true; | ||
| if (workspaceEdit.documentChanges) { | ||
| for (const change of workspaceEdit.documentChanges) { | ||
| if (change.textDocument.version && change.textDocument.version >= 0) { |
There was a problem hiding this comment.
Are these checks necessary?
| applied = false; | ||
| } | ||
| } else { | ||
| applied = false; |
There was a problem hiding this comment.
Is not the whole change should be applied or rejected? It seems that changes can be applied partially by this method.
| if (change.textDocument.version && change.textDocument.version >= 0) { | ||
| const textDocument = this.documents.get(change.textDocument.uri); | ||
| if (textDocument && textDocument.version === change.textDocument.version) { | ||
| monaco.editor.getModel(monaco.Uri.parse(textDocument.uri)).pushEditOperations( |
There was a problem hiding this comment.
Should not you check that the model is defined?
|
|
||
| export class MonacoCommands implements Commands { | ||
|
|
||
| public constructor(private _editor: monaco.editor.IStandaloneCodeEditor) { } |
There was a problem hiding this comment.
protected readonly editor
| public constructor(private _editor: monaco.editor.IStandaloneCodeEditor) { } | ||
|
|
||
| public registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): Disposable { | ||
| return (this._editor as any)._commandService.addCommand(command, { |
There was a problem hiding this comment.
please introduce augmenting typings for internals instead of using any
There was a problem hiding this comment.
Could you explain what you mean here? Not sure I'm familiar with this technique.
There was a problem hiding this comment.
I meant that you should add d.ts. file that augments monaco module add exposes _commandService, look at https://github.com/theia-ide/theia/blob/master/packages/monaco/src/typings/monaco/index.d.ts.
| public registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): Disposable { | ||
| return (this._editor as any)._commandService.addCommand(command, { | ||
| handler: (id: string, ...args: any[]) => { | ||
| console.log("Executing command", command, id, args); |
There was a problem hiding this comment.
Won't it pollute console?
There was a problem hiding this comment.
Sorry, left in from testing!
| } else { | ||
| applied = false; | ||
| } | ||
| return Promise.resolve(applied); |
There was a problem hiding this comment.
Could you use high-level functions as reduce to get rid of if-else cascade?
7471a0c to
47cc839
Compare
|
I've made the changes but not written an example. Any ideas on what to use as an example?! |
|
@gatesn the same here please use rebase instead of merge |
|
I like changes but there should be a proof that it is working: tests or use of it in the example. What if the JSON server provides:
It should not be sophisticated, but only demonstrate that everything works together. |
5800486 to
6679516
Compare
|
@akosyakov I created an example that provides a code action for any document in all positions. This action triggers a server-side command that upper cases the entire document. |
1573c3d to
fad66e0
Compare
|
@gatesn I've tested this PR and it works nicely, thank you! I've opened a new PR against your, please merge it and after that, I will approve this PR. Next time you can work in the branch directly in this repo since you have the write access instead of working on the fork. It makes easy to push new commits to PRs. |
…age server Signed-off-by: Nicholas Gates <ngates@palantir.com>
4e2162c to
0cd9823
Compare
|
@akosyakov merged your changes, thanks |
|
Do you think we could cut a release after this merges? |
|
@gatesn LGTM, thank you again! |
yes, we can make a release. Should we migrate to monaco 0.10.0 before the release? |
|
btw i wonder why github cannot recognize your account as an author, see: https://github.com/TypeFox/monaco-languageclient/commits/master |
|
Probably no 0.10.0 given the breaking changes around Code actions. We might need to investigate to see what that means. |
|
And it seems my git setup is different on different laptop :/ |
Pull request TypeFox#21 added support for the workspace/applyEdit capability so it should be stated as such in the WorkspaceClientCapabilities. Signed-off-by: Remy Suen <remy.suen@gmail.com>
Pull request TypeFox#21 added support for the workspace/applyEdit capability so it should be stated as such in the WorkspaceClientCapabilities. Signed-off-by: Remy Suen <remy.suen@gmail.com>
Pull request #21 added support for the workspace/applyEdit capability so it should be stated as such in the WorkspaceClientCapabilities. Signed-off-by: Remy Suen <remy.suen@gmail.com>
This implements a basic applyEdit operation (more advanced ones would accept the editor and preserve / manipulate the current selections), as well as registering commands against a given editor.
Fixes #11
Fixes #12